package com.example.homework.homework04;

import java.util.List;

// 线程任务类
public class EntranceTask implements Runnable {
    private int num; // 编号id
    private List<String> doubleColorBalls;

    public EntranceTask(int num, List<String> doubleColorBalls) {
        this.num = num;
        this.doubleColorBalls = doubleColorBalls;
    }

    @Override
    public void run() {
        int count = 0;
        // 获取线程名称
        String name = Thread.currentThread().getName();
        while (true) {
            synchronized (this) {
                // 判断员工是否已经全部拿到双色球号码了
                if (num <= 0) {
                    break;
                }
                // 去抽取双色球
                int index = (int) (Math.random() * doubleColorBalls.size());
                System.out.println("编号为：" + num-- + " 的员工，从" + name + "入场拿到的双色球彩票的号码是" + doubleColorBalls.remove(index));
                count++;
            }
        }
        System.out.println(name + "线程抽奖了" + count + "次");
    }
}
